package com.nft.collection.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.nft.collection.domain.Collection;
import com.nft.collection.domain.CollectionStory;
import com.nft.collection.domain.MysteryBoxCommodity;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

@Data
public class MarketCollectionVo {


    private String id;

    private String name;

    private String cover;

    private Double price;

    private Integer quantity;

    @JsonFormat(pattern = "MM.dd HH:mm", timezone = "GMT+8")
    private Date createTime;

    private String creatorName;

    private String creatorAvatar;

    private Double cashbackAmount;

    private int cashbackArrivalTime;

    private List<String> storyPicLinks = new ArrayList<>();

  private String  lockPayMemberId ;

    private List<MysteryBoxCommodityVO> subCommoditys = new ArrayList<>();

    public static MarketCollectionVo convertForShiChang(Collection po) {
        if (po == null) {
            return null;
        }
        MarketCollectionVo vo = new MarketCollectionVo();
        BeanUtils.copyProperties(po, vo);
//		long surplusSecond = DateUtil.between(new Date(), po.getSaleTime(), DateUnit.SECOND, false);
//		vo.setSurplusSecond(surplusSecond > 0 ? surplusSecond : 0);
        if (po.getCreator() != null) {
            vo.setCreatorName(po.getCreator().getName());
            vo.setCreatorAvatar(po.getCreator().getAvatar());
        }
        for (CollectionStory collectionStory : po.getCollectionStorys()) {
            vo.getStoryPicLinks().add(collectionStory.getPicLink());
        }
        Set<MysteryBoxCommodity> mysteryBoxCommoditys = po.getSubCommoditys();
        for (MysteryBoxCommodity mysteryBoxCommodity : mysteryBoxCommoditys) {
            vo.getSubCommoditys().add(MysteryBoxCommodityVO.convertFor(mysteryBoxCommodity));
        }
        return vo;
    }

}
